package com.example.demo.utils;

import java.util.Collection;

/**
 * @author xiongshiyan at 2019/3/6 , contact me with email yanshixiong@126.com or phone 15208384257
 */
public class ArrayUtil {
    private ArrayUtil(){}

    /**
     * 检查某个值是否在集合中
     */
    public static <T> boolean targetInCollection(T target, Collection<T> collection) {
        if(null == collection || collection.isEmpty()){
            return false;
        }
        for (T s : collection) {
            if(s.equals(target)){
                return true;
            }
        }
        return false;
    }
    /**
     * 检查某个值是否在数组中
     */
    public static <T> boolean targetInArray(T target, T[] array) {
        if(null == array || array.length == 0){
            return false;
        }
        for (T s : array) {
            if(s.equals(target)){
                return true;
            }
        }
        return false;
    }
    /**
     * 检查某个值是否在数组中
     */
    public static boolean targetInArray(String target, String[] array , boolean ignoreCase) {
        if(ignoreCase){
            for (int i = 0; i < array.length; i++) {
                array[i] = array[i].toLowerCase();
            }
            return targetInArray(target.toLowerCase() , array);
        }
        return targetInArray(target, array);
    }
}
